package com.globallogic.addtoken;

import java.util.List;

import com.globallogic.draw.DrawContainer;
import com.globallogic.draw.Square;
import com.globallogic.inout.Out;
import com.globallogic.token.TokenHandler;
import com.globallogic.token.TokenProcessor;

public class TokenHandlerSquare implements TokenHandler {

	@Override
	public void execute(TokenProcessor tokenProcessor, List<String> params) {
		
		if (parceParams(params)) {

			DrawContainer.getInstance().addDrawObject(new Square(side));
			Out.printLn("Square with side " + side + " has been added.");
		    
		}
			
	}
	
	private boolean parceParams(List<String> params) {

		if (params.size() == 0) {
            
			Out.printLn("Not enought parameters for creating Square");
            return false;
			
		} 			
		
		
		try {

			side = Integer.parseInt(params.get(0));
			
		    if (side < 0) {
		    	
		    	Out.printLn("Side should be a positive integer value");
                return false;		    	
		    }
			
		    return true;
		    
		} catch (NumberFormatException e) {
			
			Out.printLn("Side should be an integer value");
			
		}
		
		return false;
		
	}
	
	private int side;

}

